//
// Created by denglibin on 2021/3/26.
// 事件循环
#include <SDL.h>
static int run  = 1;
/**
 * 事件循环
 */
static void eventLoop(){
    SDL_Event  event;
    while (run)
    {//主消息循环
        SDL_WaitEvent(&event); //阻塞
        //SDL_PollEvent(&event);
        SDL_Log("event type: %d\n", event.type);
        switch (event.type)
        {
            //用户从菜单要求退出程序
            case SDL_QUIT:
                run = 0;
                break;
            default:
                break;
        }
    }
    SDL_Quit();
}

static int showWindow(){
    //初始化，成功返回0
    if (SDL_Init(SDL_INIT_VIDEO)) {
        SDL_Log("Can not init video %s\n", SDL_GetError());
        return 1;
    }
    SDL_Window * win = SDL_CreateWindow("Hello World",
                                        SDL_WINDOWPOS_CENTERED,
                                        SDL_WINDOWPOS_CENTERED,
                                        400,
                                        300,
                                        SDL_WINDOW_SHOWN
    );
    if (win == NULL) {
        SDL_Log("Can not create window %s\n", SDL_GetError());
        return 2;
    }
    eventLoop();

}
int main2_2(int argc, char* argv[]){
    return showWindow();

}

